$(function(){

    //加载页头
    $("#header").load("header.html",function(){
        $(".headerRight").find("li:nth-child(3)").addClass("active");
        //显示时间
        updateTime();
    });



    //获得当前数据
    function getCurrentTime(){
        var date=new Date();
        var day=date.getDate();
        var month=date.getMonth()+1;
        var hour=date.getHours();
        var minite=date.getMinutes();
        switch(true){
            case minite>50: minite=50;
            break;
            case minite>40: minite=40;
                break;
            case minite>30: minite=30;
                break;
            case minite>20: minite=20;
                break;
            case minite>10: minite=10;
                break;
            default :  minite="00";
                break;
        }
        hour=hour>9?hour:'0'+hour;
        month=month>9?month:'0'+month;
        day=day>9?day:'0'+day;
        return date.getFullYear()+'/'+month+'/'+day+' '+hour+":"+minite
    }
    var time=getCurrentTime();
    v.pubTimeDisplay.val(time);


    //不同时间获取数据
    function ajaxHour(time,hour){
        var str=time.replace(/\//g,"").replace(" ","").replace(/:/g,"")+"00";
        var productcategory={
            year:str,
            hour:hour,
        };
        grid_controller(productcategory);
    }

    //加载雷电控件
    function grid_controller(productcategory){
        var mapProductOptions = {
            productcategory: 'lightning',
            time: productcategory.year,
            regioncode: '330000',
            method: 'RADA_L3_MST_Lightning',
            interface: 'getContourByTimeAndRegionCode',
            key: 'zjwlzx',
            pwd: '123',
            level: 0,
            validtime: productcategory.hour,
            gridmethod: 'RADA_L3_MST_Lightning',
            gridinterface: 'getRadarGridInRectByTimeAndLevelAndValidtime',
            nlat: 55,
            slat: 18,
            wlon: 116,
            elon: 125,
            isshowzero: false,
            isshowcontrol: true,
            position: "topright",
            isforecast: true,
            isshowgridselect: false
        }
        var product = QXMap.addVectorMapProduct(mapProductOptions, function (data) {
            console.log(data);
            if (data == null) return;
        });
    }



    //切换选择时间
    v.console.find("ul").on("click","li",function(){
        var val=$(this).children("input").prop("checked",true).val();
        if(val=="oneHour")ajaxHour(time,"60");
        else if(val=="twoHour")ajaxHour(time,"120");
        else if(val=="threeHour")ajaxHour(time,"180");
        else if(val=="fourHour")ajaxHour(time,"240");
        else if(val=="fiveHour")ajaxHour(time,"300");
        else if(val=="sixHour")ajaxHour(time,"360");
    })

    ajaxHour(time,"0");

})

